package com.wangxiaonan.wxwork.service.impl;

import com.wangxiaonan.wxwork.domain.MessageTemplate;
import com.wangxiaonan.wxwork.exeption.ServiceException;
import com.wangxiaonan.wxwork.repository.MessageTemplateDao;
import com.wangxiaonan.wxwork.service.MessageTemplateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class MessageTemplateServiceImpl implements MessageTemplateService {
    private static final Logger logger = LoggerFactory.getLogger(MessageTemplateServiceImpl.class);

    @Resource
    private MessageTemplateDao messageTemplateDao;

    @Override
    public MessageTemplate getById(Integer id) {
        if (id == null) {
            throw new ServiceException("param_invalid", "参数不能为空");
        }
        return messageTemplateDao.selectByPrimaryKey(id);
    }

    @Override
    public int deleteById(Integer id) {
        if (id == null) {
            throw new ServiceException("param_invalid", "参数不能为空");
        }
        return messageTemplateDao.deleteByPrimaryKey(id);
    }

    @Override
    public int updateById(MessageTemplate messageTemplate) {
        if (messageTemplate == null || messageTemplate.getId() == null) {
            throw new ServiceException("param_invalid", "参数不能为空");
        }
        return messageTemplateDao.updateByPrimaryKeySelective(messageTemplate);
    }

    @Override
    public int save(MessageTemplate messageTemplate) {
        if (messageTemplate == null) {
            throw new ServiceException("param_invalid", "参数不能为空");
        }
        return messageTemplateDao.insert(messageTemplate);
    }
}
